<?php

require_once("../pdo/groups.php");

class GroupsTest
{
	public $Groups;
	
	public function test_get_by_instance($instance)
	{
		return $this->Groups->get_by_instance($instance);
	}

	public function test_insert($instance,$teacher)
	{
		return $this->Groups->insert($instance,$teacher);
	}
	
	public function test_update($group,$teacher)
	{
		return $this->Groups->update($group,$teacher);
	}
	
	public function test_delete($group)
	{
		return $this->Groups->delete($group);
	}
	
	public function test($pdo,$instance,$teacher1,$teacher2)
	{
		$this->Groups = new Groups(); $this->Groups->pdo = $pdo;
	
		echo "Kokeillaan muokata ryhmiä arvoilla<ul>";
		echo "<li>instance = " . $instance . "</li>";
		echo "<li>location = " . $teacher1 . " ja " . $teacher2 . "</li>";
		echo "</ul><ol>";
	
		if($this->test_insert($instance,$teacher1))
			echo "<li>Lisäys onnistui!</li>";
		
		$groups = $this->test_get_by_instance($instance);		
		$id = null;	
		foreach($groups as &$group)
			if($group->superviser_id == $teacher1)
			{
				$id = $group->id;
				break;
			}
		if($id != null)
			echo "<li>Lisätty ryhmä löytyi!</li>";
		
		if($this->test_update($id,$teacher2))
			echo "<li>Muokkaus onnistui!</li>";
		
		$groups = $this->test_get_by_instance($instance);
		$id = null;	
		foreach($groups as &$group)
			if($group->superviser_id == $teacher2)
			{
				$id = $group->id;
				break;
			}
		if($id != null)
			echo "<li>Muokattu ryhmä löytyi!</li>";
		
		if($this->test_delete($id))
			echo "<li>Poisto onnistui!</li>";
		
		$groups = $this->test_get_by_instance($instance);
		$id = null;
		foreach($groups as &$group)
			if($group->superviser_id == $teacher2)
			{
				$id = $group->id;
				break;
			}
		if($id == null)
			echo "<li>Poistettu ryhmä hävisi taulukosta!</li>";
		
		echo "</ol>";
	}
}

?>
